/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include "Hogshead.Common.h"
#include "Hogshead.Core.h"
#include "../DataStructures/ConstantBuffer/ConstantBufferGroup.h"
#include "../DataStructures/Particle.h"


namespace Hogshead
{
	namespace DX11Rendering
	{

		class Technique;
		class Texture;
		class PixelShader;
		class GeometryShader;
		class VertexShader;
		class MeshRenderer;
		class DX11Director;
		enum Primitive;
		

		class ParticleSystem : public IComponent
		{
			ComponentH(Hogshead::DX11Rendering::ParticleSystem, ParticleSystem)
		public:
			ParticleSystem(void);
			~ParticleSystem(void);
			
			void initialize();

			Vector4 getPosition();

			IComponent* readXML(const String& in_xml);

			virtual void update(const GameTimer& in_gt);

			void ParticleSystem::message(const IMessage* in_message);			

			ConstantBufferGroup _particle_info;

			void onSetActive();
			void onSetInactive();

		private:

			int _mesh_id;
			int _clone_key;
			static void handle_enabled_message(IMessageReceiver*, IMessage*);
			static void handle_pulse_message(IMessageReceiver*, IMessage*);
			static void handle_attributes_message(IMessageReceiver*, IMessage*);

			bool _never_cull;
			HashTable<String, Technique*> all_techniques;

			int _process_handle;
			String _velocity_space, _birth_space;
			bool _z_orient;
			//Vector4

			int _max_particles;

			bool _alerted;
			//The number of emitters created in the particle system
			int _num_emitters;

			//flag for alpha blending the ParticleSystem
			//This is necessary so that we draw all alpha blended particle systems before
			//additive blending systems
			String _blending;

			String _mesh_renderer_name;
			MeshRenderer* _mesh_renderer;

			ConstantBufferModifier* _modifier_message;
			Vector<void*> _change_data;
			Vector<String> _change_names;
			Vector<Primitive> _types;

			DX11Director* _dx11_director;

			bool _init_run;

			float _game_time;
			float _time_step;
			Vector4 _cam_up;
			Vector4 _cam_right;
			Vector4 _cam_forward;
			Matrix4 _rot_matrix;

			float _enabled;
			Vector2 _rotation;

			float _pulse_time;

			Texture* _texture;

			String _mesh_filter_key;
		};

	}
}